use bytes::Bytes;
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::oneshot::Sender;
use rpc::connection_manager::event::{ConnectionEvent, ConnectionManageable, ResponseData, WriteData};
use rpc::{ChannelId, RpcResult};

#[derive(Debug)]
pub enum ConnectionMessage {

    /// 掉线
    Disconnection(ChannelId),

    Write(WriteData),

    NewConnection{
        connection_id: ChannelId,
        sender: UnboundedSender<Bytes>,
        recv_sender: Sender<bool>
    },

    Response(ResponseData),
}

impl ConnectionEvent for ConnectionMessage {

    fn handle(self, manager: &mut dyn ConnectionManageable) -> RpcResult<()> {
        manager.handle_event(Box::new(self));
        Ok(())
    }
}